package com.sanley.coronavirus.dao;


import com.sanley.coronavirus.bo.ReportBO;
import com.sanley.coronavirus.entity.Base;
import com.sanley.coronavirus.entity.Report;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReportDao {

    @Insert("insert into report (outDate,returnDate,isOutProvince,isOutCity,outReason,outMethod,destination,userId,reportTime) values (#{outDate},#{returnDate},#{isOutProvince},#{isOutCity},#{outReason},#{outMethod},#{destination},#{userId},#{reportTime})")
    int add(Report report);

    @Select("select * from report where userId=#{userId}")
    List<Report> getReportByUserId(int userId);


    @Select("<script> select r.id as rid,r.outDate,r.returnDate,r.isOutProvince,r.isOutCity,r.outReason,r.outMethod,r.destination,r.reportTime,r.userId from report as r join user as u on r.userId=u.id join base as b on b.id=u.baseId <if test='keyword!=null'>where b.name like concat( '%' , #{keyword}, '%')</if></script>")
    @Results({
            @Result(property = "id",column = "rid"),
            @Result(property = "outDate",column = "outDate"),
            @Result(property = "returnDate",column = "returnDate"),
            @Result(property = "isOutProvince",column = "isOutProvince"),
            @Result(property = "isOutCity",column = "isOutCity"),
            @Result(property = "outReason",column = "outReason"),
            @Result(property = "outMethod",column = "outMethod"),
            @Result(property = "destination",column = "destination"),
            @Result(property = "reportTime",column = "reportTime"),
            @Result(property = "userId",column = "userId"),
            @Result(property = "base", column = "userId", javaType = Base.class, one = @One(select = "com.sanley.coronavirus.dao.BaseDao.findByUserId"))
    })
    List<ReportBO> listAll(String keyword);
}

